package cn.bdqn.service.impl;

import cn.bdqn.mapper.StoragedanMapper;
import cn.bdqn.service.TimerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class TimeServiceImpl implements TimerService {
    @Autowired
    StoragedanMapper storagedanMapper;
    /*
    定时向数据库发送请求
     根据有效日期和当前时间作比较
     修改药品的有效状态为失效
     每天0点进行修改
    */
    @Scheduled(cron = "0 0 0 * * ?")
    @Override
    public void updateEffectiveStatus1() {
        try {
            storagedanMapper.updateEffectiveStatus1();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /*
   定时向数据库发送请求
    根据有效日期和当前时间作比较
    修改药品的有效状态为即将失效
    每天0点进行修改
   */
    @Scheduled(cron = "0 0 0 * * ?")
    @Override
    public void updateEffectiveStatus2() {
        try {
            storagedanMapper.updateEffectiveStatus2();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
    /*
     定期删除药品数量为0的药品记录
     时间为每周五下午六点清理一次
     */
    @Scheduled(cron = "0 0 18 ? * FRI")
    @Override
    public void deleteByDanStorageNumber() {
        try {
            storagedanMapper.deleteByDanStorageNumber();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
